package com.tjetc.view;

import com.tjetc.domain.Admin;
import com.tjetc.domain.Animal;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.AnimalService;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

public class AnimalView {
    private static Scanner sc=new Scanner(System.in);
    private static AnimalService animalService= ClientProxy.getProxyInstance(AnimalService.class);
    private static CategoryView categoryView=new CategoryView();
    public void start() {
       while (true){
           System.out.println("1.动物列表");
           System.out.println("2.添加动物信息（品种、年龄、健康状况等）");
           System.out.println("3.修改动物信息");
           System.out.println("4.删除动物信息（标记为已领养或移除）");
           System.out.println("0.返回上一级");
           System.out.println("请输入你的选择0~4");
           int i = sc.nextInt();
           switch (i) {
               case 1:
                   list();
                   break;
               case 2:
                   add();
                   break;
               case 3:
                   update();
                   break;
               case 4:
                   delete();
                   break;
               case 0:
                   return;
               default:
                   System.out.println("请重新输入");
           }
       }


    }

    public void delete() {
        list();
        System.out.println("请输入将要的id");
        int id=sc.nextInt();
        Result result=animalService.update(new Animal().setId(id).setAdopted(1));
        System.out.println(result.getMsg());
    }

    public void update() {
        list();
        System.out.println("请输入id");
        int id= sc.nextInt();
        categoryView.list();
        System.out.println("请输入种类");
        int cid= sc.nextInt();
        System.out.println("请输入品种详情");
        String breed =sc.next();
        System.out.println("请输入年龄");
        int age=sc.nextInt();
        System.out.println("请输入状态");
        String status= sc.next();
        Result result=animalService.update(new Animal(id,cid,breed,age,status,0,null));
        System.out.println(result.getMsg());
    }

    public void add() {
        categoryView.list();
        System.out.println("请输入种类");
        int cid= sc.nextInt();
        System.out.println("请输入品种详情");
        String breed =sc.next();
        System.out.println("请输入年龄");
        int age=sc.nextInt();
        System.out.println("请输入状态");
        String status= sc.next();
        Result result=animalService.add(new Animal().setCid(cid).setBreed(breed).setAge(age).setStatus(status).setAdopted(0));
        System.out.println(result.getMsg());

    }

    public void list() {
        Result result = animalService.list();
        List<Animal> list = (List<Animal>) result.getData();
        if (list.size() > 0) {
            for (Animal animal : list) {
                System.out.print("品种:"+animal.getBreed()+",年龄"+animal.getAge()+",状态:"+animal.getStatus());
                if (animal.getPark()==null){
                    System.out.println();
                }else {
                    System.out.println("正处于"+animal.getPark().getDescription()+"园区");
                }
            }
        } else {
            System.out.println("没人啊");
        }
    }
}
